package mSocket.NettyImooc;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Author: Jie
 * @Date: 2018/12/22 18:35
 * @Function :程序的的入口，入则启动应用
 */
public class NettyStartMain {
    //psvm  psvm 也就是public static void main的首字母。
    public static void main(String[] args) {
        EventLoopGroup bosseGroup = new NioEventLoopGroup();
        EventLoopGroup workGroup = new NioEventLoopGroup();
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.group(bosseGroup,workGroup);
            b.channel(NioServerSocketChannel.class);
            b.childHandler(new MyWebSocketChannelHanler());
            System.out.println("server wait client connect ...");
            Channel channel = b.bind(8888).sync().channel();//绑定端口
            channel.closeFuture().sync();

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //优雅退出程序
            bosseGroup.shutdownGracefully();
            workGroup.shutdownGracefully();
            System.out.println("优雅退出程序...");
        }

    }
}
